package com.neusoft.resturant.controller;

import com.neusoft.resturant.common.utils.R;
import com.neusoft.resturant.entity.ResCollect;
import com.neusoft.resturant.service.IResCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: resturant
 * @description:
 * @author: lydms
 * @create: 2023-12-15 22:00
 **/


@RestController
@RequestMapping("/api/collect")
public class ResCollectController extends BaseController {

    @Autowired
    private IResCollectService resCollectService;

    @GetMapping("/list")
    public R list(ResCollect resCollect) {
        resCollect.setUserId(this.getUserId());
        List<ResCollect> list = resCollectService.selectResCollectList(resCollect);
        return R.success(list);
    }

    @GetMapping("/isCollect")
    public R isCollect(ResCollect resCollect) {
        resCollect.setUserId(this.getUserId());
        List<ResCollect> list = resCollectService.selectResCollectList(resCollect);
        if (list.size() == 0) {
            return R.success().put("isCollect", "0");
        }
        return R.success().put("isCollect", "1");
    }

    @PostMapping ("/addCollrct")
    public R addCollect(@RequestBody ResCollect resCollect){
        resCollect.setUserId(this.getUserId());
        resCollectService.addCollect(resCollect);
        return R.success("成功添加");
    }

    @DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        resCollectService.deleteResCollectByIds(ids);
        return R.success("删除成功");
    }


}